﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BdClient;
using Univer.Model;

namespace Univer
{
    public partial class ClientForm : Form
    {
        private readonly BdExecute _execute;
        private Client currentClient;

        public ClientForm()
        {
            _execute = new BdExecute();
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var client = _execute.GetClient(textBox1.Text, Convert.ToDecimal(textBox4.Text));
            if (client!=null)
            
            currentClient = new Client(client.id, 
                client.Phone,
                client.Passport,
                client.Name,
                client.SecondName,
                client.Patronymic);
            
        
            if (client==null)
            {
                /*клиент не найден по фамилии и паспорту, тогда ввести остальные данные о клиенте*/
                groupBox2.Enabled = true;
                groupBox3.Visible = false;
               
            }
            else
            {
                groupBox2.Enabled = false;
                textBox2.Text = client.Name;
                textBox3.Text = client.Patronymic;
                textBox5.Text = client.Phone.ToString();
                textBox6.Text = textBox1.Text;
                groupBox3.Visible = true;
              
                // вывести на главную форму имя клиента и его скидку           
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
             var id=_execute.AddClient(textBox2.Text,textBox1.Text,textBox3.Text,Convert.ToDecimal(textBox4.Text),Convert.ToDecimal(textBox5.Text));
        }

        private void button3_Click(object sender, EventArgs e)
        {

            Manager.getInstance().result = currentClient;
            Manager.getInstance().mainFormCallback.updateClientInfo();
            Close();
        }
    }
}
